package com.monkey.luffer.springboot.demo.basis.designPatterns.proxy;

import java.lang.reflect.Proxy;

/**
 * @Author: dengkaibing
 * @Description:
 * @Date: 2021/2/3 10:16
 * @company 甜橙金融
 * @Version: 1.0
 */
public class ProxyTest {
    public static void main(String[] args) {
//        //代理模式之静态代理
//        BuyHouseService buyHouseService=new ProxyBuyHouseImpl(new BuyHouseServiceImpl());
//        buyHouseService.buyHouse();
        BuyHouseService buyHouseService1=new BuyHouseServiceImpl();
        //动态代理
        buyHouseService1=(BuyHouseService)Proxy.newProxyInstance(BuyHouseServiceImpl.class.getClassLoader(),
            BuyHouseServiceImpl.class.getInterfaces(),new DynamicProxyHandlerImpl(buyHouseService1));
        buyHouseService1.buyHouse();
//        //CGLIB代理
        BuyHouseService buyHouseService3=new BuyHouseServiceImpl();
        BuyHouseServiceImpl bglibProxy=(BuyHouseServiceImpl)new CglibProxy(buyHouseService3).getInstance();
//        bglibProxy.buyHouse();
//
    }
}
